package com.hptpd.questionnairesurvey.vo;

import com.google.common.collect.Lists;
import com.hptpd.questionnairesurvey.domain.Department;
import com.hptpd.questionnairesurvey.domain.User;
import com.hptpd.questionnairesurvey.utils.AbstractMyBeanUtils;
import lombok.Data;

import java.util.List;
import java.util.Stack;

/**
 * \* Created with IntelliJ IDEA.
 * \* Date: 2019/10/28
 * \*
 * \* Description:
 * \
 *
 * @author walter_long
 */
@Data
public class UserTreeVo {
    private String id;

    private String name;

    private String type;

    private List<UserTreeVo> children;

    public static UserTreeVo convertUser(User user) {
        UserTreeVo userTreeVo = new UserTreeVo();
        userTreeVo.setId(user.getId());
        userTreeVo.setName(user.getRealName());
        userTreeVo.setType("user");
        return userTreeVo;
    }
    public static List<UserTreeVo> convertUser(List<User> users) {
        List<UserTreeVo> userTreeVos = Lists.newLinkedList();
        for (User user : users) {
            userTreeVos.add(convertUser(user));
        }
        return userTreeVos;
    }

    public static UserTreeVo convertDepartment(Department department) {
        UserTreeVo userTreeVo = new UserTreeVo();
        userTreeVo.setId(department.getId().toString());
        userTreeVo.setName(department.getName());
        userTreeVo.setType("department");
        return userTreeVo;
    }
    public static List<UserTreeVo> convertDepartment(List<Department> departments) {
        List<UserTreeVo> userTreeVos = Lists.newLinkedList();
        for (Department department : departments) {
            userTreeVos.add(convertDepartment(department));
        }
        return userTreeVos;
    }
}
